<!DOCTYPE html>
<html lang="en">
<head th:include="certificateWeb/headFoot :: headerCss">
</head>
<link rel="stylesheet" href="/css/certificateWeb/stationApplyFor/stationApplyFor.css">

<body id="body">
<div th:include="certificateWeb/headFoot :: header"></div>
<main id="main">
    <section class="sec_1">
        <div class="div_1">
            <ul>
                <li><a href="/certificate/my">个人信息</a></li>
                <li><a href="/certificate/findApplyExam">报名记录</a></li>
                <li class="this"><a href="/certificate/expertRecordList">专家申请记录</a></li>
                <li><a href="/certificate/stationRecordList">站点申请记录</a></li>
                <li><a href="/certificate/gradeQuery">成绩查询</a></li>
            </ul>
        </div>
        <div class="div_2">
            <label class="label_title">专家申请记录—专家修改</label>
            <hr/>
            <form id="formId">
                <span style="height: 50px;margin-left: 20px;font-size: 16px;line-height: 50px;color: #D52525;">注意：如要修改已有的个人信息请到个人资料修改，<a
                        style="border:1px solid #ff751a ;padding: 2px 4px;color:#ff751a"
                        href="/certificate/editMy">去修改</a></span>
                <div class="div_3">
                    <label class="span_1">专家类型<span style="color: #D52525">*</span>：</label>
                    <input type="hidden" name="type" id="type1" th:value="${expert.type}"/>
                    <input type="text"  class="form-control inp_1" readonly id="type" />
                    <!--<select id="type" name="type" class="form-control inp_1">
                        <option value="">请选择</option>
                        <option value="0">考评员</option>
                        <option value="1">考务员</option>
                        <option value="2">考务技术员</option>
                        <option value="3">督导员</option>
                        <option value="4">讲师</option>
                    </select>-->
                </div>
                <div class="div_3">
                    <label class="span_1">负责证书<span style="color: #D52525">*</span>：</label>
                    <input type="hidden" th:value="${expert.profileId}" id="profileId1">
                    <select id="profileId" name="profileId" class="form-control inp_1">
                    </select>
                </div>
<!--                <div class="div_3">-->
<!--                    <label class="span_1">知识点领域<span style="color: #D52525">*</span>：</label>-->
<!--                    &lt;!&ndash;<input id="kpointsId" th:value="${expert.kpointsId}" name="kpointsId" class="form-control inp_1"-->
<!--                           placeholder="请选择知识点领域"-->
<!--                           type="text">&ndash;&gt;-->
<!--                    <input type="hidden" th:value="${expert.kpointsId}" id="kpointsId1" />-->
<!--                    <select name="kpointsId" id="kpointsId" class="form-control inp_1"></select>-->
<!--                </div>-->
                <div class="div_3">
                <label class="span_1">个人荣誉<span style="color: #D52525"></span>：</label>
                    <textarea id="honor" maxlength="250"  name="honor" th:text="${expert.honor}"
                              class="form-control" style="width: 350px;height:250px;float: left;margin: 20px auto auto auto;"
                              placeholder="请输个人荣誉"></textarea>
                    <div style="clear:both"></div>
                 </div>
                <div class="div_3">
                    <label class="span_1">附件<span style="color: #D52525">*</span>：</label>
                    <button type="button" class="btn inp_1" style="margin-top: 20px" id="btnUpload">
                        <i class="fa fa-cloud"></i>重新上传文件
                    </button>
                    <input type="text" style="opacity:0;width: 1px;" id="fileUrl" th:value="${expert.enclosure}"
                           name="enclosure"/>
                    <span id="test" style="display: block;"></span>
                </div>
                <div class="div_3" th:each="xz:${consultations}">
                    <label class="span_1">附件模板下载：</label>
                    <label style="height: 50px;float: left;margin: 20px 10px auto auto;font-size: 16px;line-height: 50px;">
                        <a target="_blank" style="color: blue" download th:href="${xz.files}" th:text="${xz.title}"></a>
                    </label>
                </div>
                <input type="hidden" th:value="${expert.id}" name="expertId"/>
                <div class="div_3">
                    <button class="form-control but_1" id="send" type="submit">提交</button>
                </div>
            </form>
        </div>
        <div style="clear: both"></div>
    </section>
</main>
<div th:include="certificateWeb/headFoot :: footer"></div>
<script src="/js/plugins/validate/jquery.validate.extend.js"></script>
</body>
<script>
    $(function () {

        if ($("#type1").val() == 0){
            $('#type').val("考评员")
        }else if ($("#type1").val() == 1){
            $('#type').val("考务员")
        }else if ($("#type1").val() == 2){
            $('#type').val("考务技术员")
        }else if ($("#type1").val() == 3){
            $('#type').val("督导员")
        }else if ($("#type1").val() == 4){
            $('#type').val("讲师")
        }

        validateRule();
         //$("#kpointsId").val($("#kpointsId1").val());
         // $("#type").val($("#type1").val());
        if ($("#fileUrl").val() != '') {
            $("#test").html(subFileName($("#fileUrl").val()))
        }
          $.ajax({
            url: '/jzApi/certificates/selProfileFill',
            success: function (res) {
                var list = res.data;
                var profileId1 = $("#profileId1").val();
                var opt = '<option value="">请选择</option>';
                for (var i = 0; i < list.length; i++) {
                    if (profileId1 == list[i].id) {
                        opt += '<option selected value="' + list[i].id + '">' + list[i].name + '</option>'
                    } else {
                        opt += '<option value="' + list[i].id + '">' + list[i].name + '</option>'
                    }
                }
                $("#profileId").html(opt);
            }
        })

        // $.ajax({
        //     url: '/certificate/findKonwledge',
        //     data:{profileId:$("#profileId1").val()},
        //     success: function (res) {
        //         var list = res.data;
        //         console.log("res = ", res.data);
        //         var kpointsId1 =  $("#kpointsId1").val();
        //         var opt = '<option value="">请选择</option>';
        //         for (var i = 0; i < list.length; i++) {
        //             if (kpointsId1 == list[i].id){
        //                 opt += '<option selected value="' + list[i].id + '">' + list[i].name + '</option>'
        //             }else {
        //                 opt += '<option value="' + list[i].id + '">' + list[i].name + '</option>'
        //             }
        //
        //         }
        //         $("#kpointsId").html(opt);
        //     }
        // })

    // $("#profileId").change(function () {
    //     var profileId = $("#profileId").val();
    //         $.ajax({
    //             url: '/certificate/findKonwledge',
    //             data:{profileId:profileId},
    //             success: function (res) {
    //                 var list = res.data;
    //                 console.log("res = ", res.data);
    //                 var opt = '<option value="">请选择</option>';
    //                 for (var i = 0; i < list.length; i++) {
    //                     opt += '<option value="' + list[i].id + '">' + list[i].name + '</option>'
    //                 }
    //                 $("#kpointsId").html(opt);
    //             }
    //         })
    // })
    });
    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });
        //保存信息
      function save() {
        ajaxTokenForm("/jzApi/experts/editExpert", "POST", $('#formId').serialize(), function (res) {
             location.href = '/certificate/expertRecordList';
        })
    }

    layui.use(['upload', 'laydate'], function () {
        var upload = layui.upload;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#dateOfBirth' //指定元素
        });

        upload.render({
            elem: '#btnUpload', //绑定元素
            url: '/jzApi/utils/fileImprot', //上传接口
            size: 1024 * 4,
            accept: 'file',
            done: function (r) {
                $("#fileUrl").val(r.data);
                $("#test").html(subFileName(r.data));
            },
            error: function (r) {
                layer.msg(r.msg);
            }
        });
    });

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i>";
        $("#formId").validate({
            rules: {
                type: {
                    required: true
                },
                profileId: {
                    required: true
                },
                enclosure: {
                    required: true
                }
            },
            messages: {
                type: {
                    required: icon + "请选择专家类型"
                },
                profileId: {
                    required: icon + "请选择证书"
                },
                enclosure: {
                    required: icon + "请上传附件"
                }

            }
        })
    }
</script>
</html>